//################################
// 版权所有：鸽子游戏俱乐部
// 系统名称：鸽子游戏俱乐部-移动版
// 文件名称：loginService.js
// 创建时间：2017年07月03日
// 创建人员：Lemo
// 功能说明：login service
//################################

'use strict';

import Config from '../common/config';
import {CommonFunc, CommonData} from '../common';
import { request } from '../utils/requestUtil';

import DeviceInfo from 'react-native-device-info';

function logon(username, password) {
    return new Promise((resolve, reject) => {
        let formData = new FormData();
        formData.append('username',username);
        formData.append('password',password);
        formData.append('appVersion',CommonData.appVersion);
        let params = {};
        params.timeout = 5000;
        params.method = 'post';
        params.postType = 'json';
        params.url = CommonFunc.getUrlConfig('logonUrl', 'login');
        params.params = formData;

        request(params)
        .then((responseData) => {
            if (responseData.code=='200') {
                let result = {
                    data: responseData.data,
                    code: responseData.code,
                }
                resolve(result);
            }
            else {
                let code = 0;
                if (responseData.code && responseData.code !== 0) {
                    code = responseData.code;
                }
                let result = {
                    info: responseData.info,
                    code: code,
                };

                reject(result);
            }
        })
        .catch((error) => {
            reject(error);
        });
    });
}

module.exports = {
    logon,
};